package com.young4j.springdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.young4j.springdemo.entity.Student;
import com.young4j.springdemo.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

/**
 * @Description
 * @Author yf
 * @Date 2019/1/7 13:59
 **/
@RestController
@RequestMapping("/mplus")
public class MybatisPlusController {
    @Autowired
    private IStudentService iStudentService;
    @RequestMapping("/list")
    public Object list(){
        List<Object> objects = iStudentService.listObjs(new QueryWrapper<>());
        return objects;
    }
    @RequestMapping("/add")
    public Object add(){
        Student s = new Student();
        s.setSid(new Random().nextLong());
        s.setSname(s.getSid().toString());
        s.setSage(new Random().nextInt() % 100);
        s.setSsex(s.getSid() % 2 == 0 ? 1 : 0);
        boolean save = iStudentService.save(s);
        return save;
    }
}
